package com.tjhzzx.ibmsSupervisor.model.common;

import com.tjhzzx.ibmsSupervisor.enums.BModuleType;
import com.tjhzzx.ibmsSupervisor.model.dashboard.BDashboardRoot;
import com.tjhzzx.ibmsSupervisor.model.menu.BTreeMenuRoot;

import javax.baja.sys.Property;
import javax.baja.sys.Sys;
import javax.baja.sys.Type;
import javax.baja.util.BFolder;
import java.util.logging.Logger;

/**
 * @author Luc
 * @date 2019-11-12 20:40
 *
 * @description 通用模块：实时数据、历史数据、告警管理。。。
 */
public class BCommonModule extends BFolder {

    private static final Logger LOGGER = Logger.getLogger(BCommonModule.class.getName());

    /**
     * @description:  title, 模块菜单显示标题
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property title = newProperty(0, "通用模块", null);

    public String getTitle() {
        return getString(title);
    }

    public void setTitle(String v) {
        setString(title, v, null);
    }


    /**
     * @description: 模块菜单显示图标，font-awesome图标
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property nIcon = newProperty(0, "area-chart", null);

    public String getNIcon() {
        return getString(nIcon);
    }

    public void setNIcon(String v) {
        setString(nIcon, v, null);
    }

    /**
     * @description: 模块类型，@see com.tjhzzx.thinkinglabSupervisor.enums.BModuleType
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property moduleType = newProperty(0, BModuleType.treeMenu, null);

    public BModuleType getModuleType() {
        return (BModuleType) get(moduleType);
    }

    public void setModuleType(BModuleType v) {
        set(moduleType, v, null);
    }

    /**
     * @description:  moduleType, 为PAGE时使用
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property pagePath = newProperty(0, "/subsystem", null);

    public String getPagePath() {
        return getString(pagePath);
    }

    public void setPagePath(String v) {
        setString(pagePath, v, null);
    }

    /**
     * @description:  moduleType, 为URL时使用
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property url = newProperty(0, "外部链接 http://", null);

    public String getUrl() {
        return getString(url);
    }

    public void setUrl(String v) {
        setString(url, v, null);
    }

    /**
     * @description:  moduleType, 为DASHBOARD时使用
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property dashboardRoot = newProperty(0, new BDashboardRoot(), null);

    public BDashboardRoot getDashboardRoot() {
        return (BDashboardRoot) get(dashboardRoot);
    }

    public void setDashboardRoot(BDashboardRoot v) {
        set(dashboardRoot, v, null);
    }

    /**
     * @description:  moduleType, 为TREE_MENU时使用
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property treeMenuRoot = newProperty(0, new BTreeMenuRoot(), null);

    public BTreeMenuRoot getTreeMenuRoot() {
        return (BTreeMenuRoot) get(treeMenuRoot);
    }

    public void setTreeMenuRoot(BTreeMenuRoot v) {
        set(treeMenuRoot, v, null);
    }

//    @Override
//    public void changed(Property property, Context context) {
//        super.changed(property, context);
//        if(property.getType() == BModuleType.TYPE) {
//            String tag = propertyValueToString(property, context);
//            if(tag.equals(BModuleType.dashboard.toString(context))) {
////                this.setFlags(this.getSlot("velocityName"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("url"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("treeMenuRoot"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("dashboardRoot"), 0, Context.commit);
//            } else if(tag.equals(BModuleType.page.toString(context))) {
//                this.setFlags(this.getSlot("url"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("treeMenuRoot"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("dashboardRoot"), Flags.HIDDEN, Context.commit);
////                this.setFlags(this.getSlot("velocityName"), 0, Context.commit);
//            } else if(tag.equals(BModuleType.url.toString(context))) {
//                this.setFlags(this.getSlot("treeMenuRoot"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("dashboardRoot"), Flags.HIDDEN, Context.commit);
////                this.setFlags(this.getSlot("velocityName"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("url"), 0, Context.commit);
//            } else {
//                this.setFlags(this.getSlot("dashboardRoot"), Flags.HIDDEN, Context.commit);
////                this.setFlags(this.getSlot("velocityName"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("url"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("treeMenuRoot"), 0, Context.commit);
//            }
//        }
//    }


    @Override
    public Type getType() { return TYPE; }
    public static final Type TYPE = Sys.loadType(BCommonModule.class);
}
